<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
Copyright 2011, 2012 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:include href="library.xslt" />

<!-- copy through all elements and their attributes -->
<xsl:template match="* | @*">
	<xsl:copy><xsl:copy-of select="@*"/><xsl:apply-templates/></xsl:copy>
</xsl:template>

<!-- add package and manifest name to top of the file -->
<xsl:template match="package">
	<xsl:element name="package">
		<xsl:attribute name="name">
			<xsl:call-template name="package-name">
				<xsl:with-param name="operation">insert</xsl:with-param>
			</xsl:call-template>
		</xsl:attribute>
		<xsl:apply-templates/>
	</xsl:element>
</xsl:template>

<!-- translate (feature|trailer|poster)/filename -->
<xsl:template match="feature/filename | trailer/filename | poster/filename">
	<xsl:element name="filename">
		<xsl:attribute name="source"><xsl:value-of select="text()"/></xsl:attribute>
		<xsl:call-template name="featuretrailerposter-filename">
			<xsl:with-param name="seq"><xsl:value-of select="count(../preceding-sibling::node()) + 1"/></xsl:with-param>
			<xsl:with-param name="filename"><xsl:value-of select="text()"/></xsl:with-param>
			<xsl:with-param name="type"><xsl:value-of select="name(..)"/></xsl:with-param>
		</xsl:call-template>
	</xsl:element>
</xsl:template>

<!-- translate (feature|trailer)/thumbnail -->
<xsl:template match="feature/thumbnail | trailer/thumbnail">
	<xsl:element name="thumbnail">
		<xsl:attribute name="source"><xsl:value-of select="text()"/></xsl:attribute>
		<xsl:call-template name="featuretrailerposter-filename">
			<xsl:with-param name="seq"><xsl:value-of select="count(../preceding-sibling::node()) + 1"/></xsl:with-param>
			<xsl:with-param name="filename"><xsl:value-of select="text()"/></xsl:with-param>
			<xsl:with-param name="type"><xsl:value-of select="name()"/></xsl:with-param>
		</xsl:call-template>
	</xsl:element>
</xsl:template>

<!-- translate (feature|trailer)/caption -->
<xsl:template match="feature/caption | trailer/caption">
	<xsl:element name="caption">
		<xsl:attribute name="source"><xsl:value-of select="text()"/></xsl:attribute>
		<xsl:attribute name="language"><xsl:value-of select="@language"/></xsl:attribute>
		<xsl:if test="@name">
			<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
		</xsl:if>
		<xsl:if test="@format">
			<xsl:attribute name="format"><xsl:value-of select="@format"/></xsl:attribute>
		</xsl:if>
		<xsl:call-template name="caption-filename">
			<xsl:with-param name="seq"><xsl:value-of select="count(../preceding-sibling::node()) + 1"/></xsl:with-param>
			<xsl:with-param name="filename"><xsl:value-of select="text()"/></xsl:with-param>
			<xsl:with-param name="language"><xsl:value-of select="@language"/></xsl:with-param>
		</xsl:call-template>
	</xsl:element>
</xsl:template>


</xsl:stylesheet>

